package JavaFoundation.myLock.locktools;

import java.util.concurrent.CountDownLatch;

/*
CountDownLatch是设置一个数，减为0后才主线程才能继续向下执行
 */
public class CountDownLatchDome {

    public static void main(String[] args) throws InterruptedException {
//        for (int i = 1; i <= 6; i++) {
//            new Thread(()->{
//                System.out.println(Thread.currentThread().getName()+"======上完自习开始走人");
//            }).start();
//        }
//        System.out.println(Thread.currentThread().getName()+"======班长关门");
        CountDownLatch countDownLatch = new CountDownLatch(6);
//        for (int i = 1; i <= 6; i++) {
//            new Thread(()->{
//                System.out.println(Thread.currentThread().getName()+"======上完自习开始走人");
//                countDownLatch.countDown();//每走一个人减1
//            },String.valueOf(i)).start();
//        }
//        countDownLatch.await();
//        System.out.println(Thread.currentThread().getName()+"======班长关门");

        for (int i = 1; i <= 6; i++) {
            new Thread(()->{
                System.out.println(Thread.currentThread().getName()+"\t 国，被灭了");
                countDownLatch.countDown();//每走一个人减1
            }, CountryEnum.for_EachCountryEnum(i).getRetMessage()).start();
        }
        countDownLatch.await();
        System.out.println(Thread.currentThread().getName()+"======秦灭六国，一统天下");
    }
}
